package com.example.dql.diary.Suspending;

import android.app.Activity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.example.dql.diary.Model.SusContentDTO;
import com.example.dql.diary.Model.SuspendingDTO;
import com.example.dql.diary.R;
import com.example.dql.diary.activity.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class SuspendingActivity extends BaseActivity {
	@BindView(R.id.recyclerView)
	RecyclerView recyclerView;
	private Activity mActivity;
	private SuspendingAdapter adapter;
	private List<SuspendingDTO> textList = new ArrayList<>();
	private List<SusContentDTO> content = new ArrayList<>();

	@Override
	public int getLayoutId() {
		return R.layout.activity_suspending;
	}

	@Override
	public Activity bindActivity() {
		return this;
	}

	@Override
	public void init() {
		mActivity = SuspendingActivity.this;
		setRecycleData();
		adapter = new SuspendingAdapter(null);
		NormalDecoration decoration = new NormalDecoration() {
			@Override
			public String getHeaderName(int position) {
				return textList.get(position).getText();
			}
		};
		//自定义布局
		decoration.setOnDecorationHeadDraw(new NormalDecoration.OnDecorationHeadDraw() {
			@Override
			public View getHeaderView(final int position) {
				final View headView = LayoutInflater.from(SuspendingActivity.this).inflate(R.layout.item_head, null);
				final TextView tvAvatar = (TextView) headView.findViewById(R.id.tv_sus_head);
				tvAvatar.setText(textList.get(position).getText());
//                decoration.loadImage(carList.get(pos).getLetter(), pos, ivAvatar);
				return headView;
			}
		});
		decoration.setOnHeaderClickListener(new NormalDecoration.OnHeaderClickListener() {
			@Override
			public void headerClick(int position) {
				Toast.makeText(SuspendingActivity.this, "点击到头部" + textList.get(position).getText(), Toast.LENGTH_SHORT).show();
			}
		});
		LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
		recyclerView.setLayoutManager(layoutManager);
		adapter.addData(content);
		recyclerView.addItemDecoration(decoration);
		recyclerView.setAdapter(adapter);
	}

	private void setRecycleData() {
		for (int i = 0 ;i < 12 ; i++){
			SusContentDTO t = new SusContentDTO("大哥大嫂过年好，你是我的爷，我是你的儿");
			content.add(t);
		}
		SuspendingDTO a = new SuspendingDTO("A");textList.add(a);
		SuspendingDTO b = new SuspendingDTO("B");textList.add(b);
		SuspendingDTO c = new SuspendingDTO("C");textList.add(c);
		SuspendingDTO d = new SuspendingDTO("D");textList.add(d);
		SuspendingDTO e = new SuspendingDTO("E");textList.add(e);
		SuspendingDTO f = new SuspendingDTO("F");textList.add(f);
		SuspendingDTO g = new SuspendingDTO("G");textList.add(g);
		SuspendingDTO h = new SuspendingDTO("H");textList.add(h);
		SuspendingDTO i = new SuspendingDTO("I");textList.add(i);
		SuspendingDTO j = new SuspendingDTO("J");textList.add(j);
		SuspendingDTO k = new SuspendingDTO("K");textList.add(k);
		SuspendingDTO l = new SuspendingDTO("L");textList.add(l);

	}


}
